package com.ruoyi.project.hcy.notice.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.hcy.notice.domain.NoticeType;
import com.ruoyi.project.hcy.notice.service.INoticeTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("notice/type")
public class NoticeTypeController extends BaseController {

    @Autowired
    private INoticeTypeService noticeTypeService;


    private String prefix="hcy/notice";

    @RequiresPermissions("notice:type:view")
    @GetMapping()
    public String type()
    {

        return prefix + "/type";
    }
    @RequiresPermissions("notice:type:list")
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(NoticeType noticeType){

        startPage();
        List<NoticeType> list = noticeTypeService.selectNoticeTypeList(noticeType);
        return getDataTable(list);

    }

    /**
     * 新增公告类型
     * @return
     */
    @GetMapping("/add")
    public String typeAdd()
    {

        return prefix + "/typeAdd";
    }

    @RequiresPermissions("notice:type:add")
//    @Log(title = "岗位管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated NoticeType noticeType)
    {

        return toAjax(noticeTypeService.insertNoticeType(noticeType));
    }


    /**
     * 删除
     * @param ids
     * @return
     */
    @RequiresPermissions("notice:type:remove")
//    @Log(title = "岗位管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        try
        {
            return toAjax(noticeTypeService.deleteNoticeTypeByIds(ids));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }


    /**
     * 修改岗位
     */
    @GetMapping("/edit/{typeId}")
    public String edit(@PathVariable("typeId") Integer typeId, ModelMap mmap)
    {
        mmap.put("noticeType", noticeTypeService.selectNoticeTypeById(typeId));
        return prefix + "/typeEdit";
    }
    /**
     * 修改保存岗位
     */
    @RequiresPermissions("notice:type:edit")
//    @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated NoticeType noticeType)
    {
        return toAjax(noticeTypeService.updateNoticeType(noticeType));
    }





}
